
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
 */
package nac.firefight;

//~--- JDK imports ------------------------------------------------------------

import java.beans.XMLDecoder;
import java.beans.XMLEncoder;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author User
 */
public class SettingsManager {
    private GameSettings gs;

    public SettingsManager() {
        gs = new GameSettings();
    }

    private void writeDefault() {
       // gs.setFullScreen(Default.FULLSCREEN);
       // gs.setWidth(Default.WIDTH);
       // gs.setHeight(Default.HEIGHT);
        save();
    }

    public GameSettings getSettings() {
        return gs;
    }

    public void save() {
        try {
            XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("settings.xml")));

            encoder.writeObject(gs);
            encoder.close();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(SettingsManager.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void load() {
        XMLDecoder decoder;

        try {
            decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream("settings.xml")));
            gs      = (GameSettings) decoder.readObject();
            decoder.close();

            return;
        } catch (FileNotFoundException ex) {
            writeDefault();
            load();
        }
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
